#include<vector>
using namespace std;

class Solution {
public:
    bool kLengthApart(vector<int>& nums, int k) {
        int i = 0;
        while (i < nums.size()) {
            if (nums[i] == 1) {
                int j = i + 1;
                while (j < nums.size()) {
                    if (nums[j] == 1) break;
                    ++j;
                }

                if (j < nums.size() && (j - i - 1) < k) 
                    return false;
                i = j;
            }
            else
                ++i;

        }
        return true;
    }
};